package src.origintrail;

import java.util.ArrayList;

/**
 * A basic inventory
 * @param <K> Item
 * @author csmythe
 */
public class Inventory<K> {
    ArrayList <Item> contents;

    /**
     * Constructor
     */
    public Inventory() {
        contents = new ArrayList<Item>();
    }

    /**
     * Adds an Item
     * @param i The Item to add
     */
    public void addItem(Item i){
        Item entry = find(i);
        if(entry != null){
            entry.setStack(i.getStack() + entry.getStack());
            //if(entry.getStack() <= 0)
              //  entry.setStack(0);//contents.remove(entry);  
        }else{
            contents.add(i);
        }   
        
    }
    
    /**
     * Finds a specific type of Item in the contents.
     * @param query The Item sent in.
     * @return The Item in this list.
     */
    public Item find(Item query){
        for(Item i: contents)
            if(query.getClass().equals(i.getClass()))
                return i;
        return null;
    }
	
}

